package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Workflow;
import com.qidianit.mes.pro.service.WorkflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ Description:
 * @ Author:WuJingLei
 * @ Date: 2025/9/18 -14:20
 */
@RestController
@RequestMapping("/workflow")
public class WorkflowController {
    @Autowired
    private WorkflowService workflowService;

    @RequestMapping("/page")
    public Result<PageInfo<Workflow>> page(Workflow workflow,
                                            @RequestParam(defaultValue = "1") int page,
                                            @RequestParam(defaultValue = "10") int size){
        return workflowService.queryWorkflows(workflow,page,size);
    }

    @GetMapping("/code/{code}")
    public Result<Workflow> getByCode(@PathVariable String code){
        return workflowService.queryByCode(code);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Workflow workflow){
        return workflowService.saveWorkflow(workflow);
    }

    @PutMapping("/update")
    public Result updateWorkflow(@RequestBody Workflow workflow){
        return workflowService.updateWorkflow(workflow);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        return workflowService.deleteById(id);
    }

    @DeleteMapping("/batchDelete")
    public  Result batchDelete(Long[] id){
        return workflowService.batchDelete(id);
    }
}
